package org.bulu.project.person.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.bulu.project.person.dao.VideoCheckDao;
import org.bulu.project.person.service.VideoCheckService;
import org.bulu.project.system.model.bo.VideoCheckBO;
import org.bulu.project.system.model.query.VideoPageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VideoCheckServiceImpl implements VideoCheckService {

    @Autowired
    private VideoCheckDao videoMapper;

    @Override
    public PageInfo listPageVideos(VideoPageQuery queryParams) {
        try{
            // 使用pageHelper插件分页
            int pageNum = queryParams.getPageNum();
            int pageSize = queryParams.getPageSize();
            PageHelper.startPage(pageNum, pageSize);
            PageInfo page = new PageInfo<>(videoMapper.videoCheckPage(queryParams));
            return page;
        }catch (Exception e){
            throw  new RuntimeException("分页查询异常");
        }

    }

    @Override
    public VideoCheckBO getVideoDetail(Integer vid) {
        try{
            if (vid != null){
                return videoMapper.getVideoDetail(vid);
            }
            throw new RuntimeException("视频id不能为空");
        }catch (Exception e){
            throw new RuntimeException("查询视频详情异常");
        }

    }

    @Override
    public int checkVideo(Integer vid, Integer status) {
        try{
            if (vid != null && status != null){
                return videoMapper.checkVideo(vid, status);
            }else{
                throw new RuntimeException("视频id和状态不能为空");
            }
        }catch (Exception e){
            throw new RuntimeException("审核视频异常");
        }
    }

    @Override
    public int deleteBatchVideo(Integer[] vid) {
        try{
            if (vid != null){
                return videoMapper.deleteByIds(vid);
            }else{
                throw new RuntimeException("视频id不能为空");
            }
        }catch (Exception e){
            throw new RuntimeException("批量删除视频异常");
        }
    }

    @Override
    public void notifyUser(Integer vid, Integer status) {
    }
}
